<?php

$_this =& $this;

/* @var $_this View */
/* @var $form FormHelper */
/* @var $editForm EditFormHelper */
/* @var $html HtmlHelper */
/* @var $ehtml EHtmlHelper */
/* @var $javascript JavascriptHelper */
/* @var $jqax JqaxHelper */
/* @var $filterBlock FilterBlock */

Page::addJS('report');

$__tool_form_id = 'select_report_form';
$__submit_button_id = 'submit_report';
$__select_tool_control_name = "data[{$modelName}][testing_id]";

foreach ($testings_list as &$testing) {
    foreach ($testing['Test']['Reports'] as &$report) {
        $report['html_price'] = $editForm->drawAmount($report['price'], 'EP');
        $report['txt_price'] = $editForm->drawAmountTXT($report['price'], 'EP');
    }
}

?><?=$editForm->create($modelName, array('id' => $__tool_form_id, 'url'=>("/candidates/{$candidate[$PKName]}/report")));?><?php
/*
	ob_start();
	?><?=$editForm->startGroup('reports_section');?><?php
        ?><?=$editForm->header(__d($po_domain, 'Reports', true));?><?php
        ?><?=$editForm->cell('<div id="reports_table"></div>', array('class' => 'non-top-margin'));?><?php
    ?><?=$editForm->endGroup();?><?php
	$reports_template = ob_get_clean();

	ob_start();
	?><?=$editForm->startGroup('reports_section');?><?php
        ?><?=$editForm->cell('');?><?php
    ?><?=$editForm->endGroup();?><?php
	$reports_empty = ob_get_clean();

	ob_start();
	?><?=$editForm->startGroup('norms_section');?><?php
        ?><?=$editForm->header(__d($po_domain, 'Norms', true));?><?php
        ?><?=$editForm->cell('<div id="norms_table"></div>', array('class' => 'non-top-margin'));?><?php
    ?><?=$editForm->endGroup();?><?php
	$norms_template = ob_get_clean();

	ob_start();
	?><?=$editForm->startGroup('norms_section');?><?php
        ?><?=$editForm->cell('');?><?php
    ?><?=$editForm->endGroup();?><?php
	$norms_empty = ob_get_clean();
*/

vendor('json');

Page::appendJSCode((
'__ToolGUIEnv = new ToolGUI('.
json::drawToComment(array(
    'select_report_control_name'    => "data[{$modelName}][report_id]",
    'select_norm_control_name'      => "data[{$modelName}][norm_id]",
    'submit_button_id'              => $__submit_button_id,
    'tool_form_id'                  => $__tool_form_id,
    'select_tool_control_name'      => $__select_tool_control_name,
    /*'reports_template'              => $reports_template,
    'reports_empty'                 => $reports_empty,
    'norms_template'                => $norms_template,
    'norms_empty'                   => $norms_empty,*/
    'reports_title'                 => __d($po_domain, 'Reports', true),
    'norms_title'                   => __d($po_domain, 'Norms', true),
    'po'                            => array(
        'confirm_begin' => __d('candidates', 'BEGIN_report_create_confirm'.(Auth::o()->is('admin') ? '_for_admin' : ''), true),
        'confirm_end' => __d('candidates', 'END_report_create_confirm', true),
        'currencyTXT' => $editForm->drawCurrencyTXT('EP'),
    ),
    'reports_headers'               => array(
        "name" => __d('reports', 'name', true),
        "price" => __d('reports', 'price', true),
    ),
    'norms_headers'               => array(
        "name" => __d('reports', 'name', true),
    ),
)).
', '.
json::drawToComment($testings_list).
');'
));?><?php

	?><?=$editForm->startSet();?><?php
		?><?=$editForm->textView(__d($po_domain, 'entity_name', true), $candidate["surname"].' / '.$candidate["name"]);?><?php
		?><?=$editForm->textView(__d($po_domain, 'group', true), $candidate['Group']["name"]);?><?php
	?><?=$editForm->endSet();?><?php



if (count($reportings)) {

    ob_start();

    ?><table class="table" cellpadding="0"><?php
    ?><thead><?php
        ?><tr><?php
            ?><th class="nw"><?php
                ?><?=__d($po_domain, 'reportings_date', true);?><?php
            ?></th><?php
            ?><th class="nw"><?php
                ?><?=__d($po_domain, 'testings_test_name', true);?><?php
            ?></th><?php
            ?><th class="nw"><?php
                ?><?=__d($po_domain, 'testings_test_type', true);?><?php
            ?></th><?php
            ?><th class=""><?php
                ?><?=__d($po_domain, 'reportings_testings_date', true);?><?php
            ?></th><?php
            ?><th class="nw"><?php
                ?><?=__d($po_domain, 'reportings_report_name', true);?><?php
            ?></th><?php
            ?><th class="nw"><?php
                ?><?=__d($po_domain, 'reportings_norm_name', true);?><?php
            ?></th><?php
            ?><th class="nw"></th><?php
        ?></tr><?php
    ?></thead><?php
    ?><tbody><?php

        $i = 0;
        foreach ($reportings as $item) {

            $class = '';
        	if ($i++ % 2 != 0) {
        		$sep = strlen($class) ? ' ' : '';
        		$class .= $sep.'altrow';
        	}
        	$class = strlen($class) ? ' class="'.$class.'"' : '';

            ?><tr <?=$class;?>><?php
        		?><td class="nw"><?php
                    ?><?=h(Date::Short(Date::SQL2UNIX($item['date']), false));?><?php
                ?></td><?php
        		?><td class="nw"><?php
                    ?><?=h($item['Test']['name']);?><?php
                ?></td><?php
        		?><td class="nw"><?php
                    ?><?=h(__d('tests', 'type_'.$item['Test']['type']));?><?php
                ?></td><?php
        		?><td class="nw"><?php
                    ?><?=h(Date::Short(Date::SQL2UNIX($item['Testing']['pass_date']), false));?><?php
                ?></td><?php
        		?><td class=""><?php
                    ?><?=h($item['Report']['name']);?><?php
                ?></td><?php
        		?><td class=""><?php
                    ?><?=h($item['Norm']['name']);?><?php
                ?></td><?php
                ?><td class="nw actions"><?php
                    ?><table class="sys_clear" cellpadding="0"><?php
                    ?><tr class="sys_clear"><?php
                     	?><?=$ehtml->iconLink("download", __d(null, 'download', true), "/candidates/{$candidate['id']}/report/{$item['id']}");?><?php
                	?></tr><?php
                    ?></table><?php
                ?></td><?php
        	?></tr><?php
        }

    ?></tbody><?php
    ?></table><?php

    $content = ob_get_clean();
    ?><?=$editForm->header(__d($po_domain, 'Reportings_header', true));?><?php
    ?><?=$editForm->cell($content, array('class' => 'non-top-margin'));?><?php
}

	ob_start();

if (count($testings_list)) {

?><table class="table" cellpadding="0"><?php
?><thead><?php
    ?><tr><?php
        ?><th class="nw"><?php
            ?><?=__d($po_domain, 'testings_test_name', true);?><?php
        ?></th><?php
        ?><th class="nw"><?php
            ?><?=__d($po_domain, 'testings_date', true);?><?php
        ?></th><?php
        ?><th class="nw"><?php
            ?><?=__d($po_domain, 'testings_test_type', true);?><?php
        ?></th><?php
        ?><th class="nw"></th><?php
    ?></tr><?php
?></thead><?php
?><tbody><?php

    $i = 0;
    foreach ($testings_list as $item) {

        $class = '';
    	if ($i++ % 2 != 0) {
    		$sep = strlen($class) ? ' ' : '';
    		$class .= $sep.'altrow';
    	}
    	$class = strlen($class) ? ' class="'.$class.'"' : '';

        ?><tr <?=$class;?>><?php
    		?><td class="nw"><?php
                ?><?=$item['Test']['name'];?><?php
            ?></td><?php
    		?><td class="nw"><?php
                ?><?=Date::Short(Date::SQL2UNIX($item['pass_date']), false);?><?php
            ?></td><?php
    		?><td class="nw"><?php
                ?><?=__d('tests', 'type_'.$item['Test']['type']);?><?php
            ?></td><?php
            ?><td class="nw"><?php
                ?><input type="radio" name="<?=$__select_tool_control_name;?>" value="<?=$item['id'];?>" /><?php
            ?></td><?php
    	?></tr><?php
    }

?></tbody><?php
?></table><?php

} else {
    ?><span class="additional_msg"><?php
        ?><?=__d($po_domain, 'testings_List is empty', true);?><?php
    ?></span><?php
}

	$content = ob_get_clean();

    ?><?=$editForm->header(__d($po_domain, 'Testings', true));?><?php
    ?><?=$editForm->cell($content, array('class' => 'non-top-margin'));?><?php

	?><?=$editForm->startGroup('reports_section');?><?php
        ?><?=$editForm->cell('');?><?php
    ?><?=$editForm->endGroup();?><?php

	?><?=$editForm->startGroup('norms_section');?><?php
        ?><?=$editForm->cell('');?><?php
    ?><?=$editForm->endGroup();?><?php


	$buttons = array();
	$buttons[] = $editForm->back(Auth::o()->is("admin") ? "/candidates/" : "/reports/");
	$buttons[] = $editForm->submitTag(__d($po_domain, 'create_report', true), array('id' => $__submit_button_id));
	if (count($buttons)) {
    	?><?=$editForm->cell(implode(' ', $buttons));?><?php
	}

?><?=$editForm->end();?><?php

?>
